﻿using UnityEngine;
using System.Collections;

namespace play {
	public class AIState : MonoBehaviour {
		public bool isAlive = true;
		
		public bool readyToFire = true;

		public bool hasInertia = false;
	

		void OnTriggerEnter2D(Collider2D c) {

			GameObject obj = c.gameObject;
			Bomb bomb = obj.GetComponent<Bomb> ();

			// 碰到了 子弹 && 是来自玩家的
			if ("BULLET".Equals(obj.tag) && bomb.isFromPlayer) {
				isAlive = false;
				Main.aliveEnemyCount--;
print ("AI dead");

				Main main = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Main>();
print ("leftEnemyCount:" + Main.leftEnemyCount);
print ("aliveEnemyCount:" + Main.aliveEnemyCount);
				if (Main.leftEnemyCount > 0) {
					main.genEnemyAfterSec(2);
				}
				else {
					if (Main.aliveEnemyCount == 0) {
						main.loadNextLevelAfterSec(1);
					}
				}
			}
		}
	}
}